home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
RollingObject.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
4KB
|
106 lines
class RollingObject extends SSObject
{
var classID = SSGlobal.CLSID_MOBILEOBJECT;
var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
var assetID = "Log";
var healthValue = -0.1;
var minVelocity = 0;
var gravity = SSGlobal.GRAVITY;
var contact = false;
var collision = false;
var editor_isItem = true;
var editor_name = "RollingObject";
var editor_args_names = ["healthValue"];
var editor_args_values = [RollingObject.prototype.healthValue];
var editor_args_types = ["number"];
var editor_args_options = [[-1,1,0.01]];
var editor_args_descriptions = [""];
var editor_args_mode = [0];
var editor_args_component = ["NumericStepper"];
function RollingObject()
{
super();
}
function onAddToWorld()
{
this.originX = this.x;
this.originY = this.y;
}
function onAddToScene()
{
this.velocity.x = this.velocity.y = 0;
this.getUpdates();
}
function onRemoveFromScene()
{
this.cancelUpdates();
this.moveTo(this.originX,this.originY,0);
this.contact = null;
}
function update(elapsed)
{
if(this.contact)
{
}
this.velocity.y += this.gravity * elapsed;
this.collision = false;
this.checkCollisions(elapsed);
this.moveBy(this.velocity.x * elapsed,this.velocity.y * elapsed,0);
}
function setContact(edge)
{
this.contact = edge;
}
function checkCollision(obj)
{
var _loc2_ = undefined;
switch(obj.classID & 4294901760)
{
case SSGlobal.CLSID_SHAPE:
if(!this.contact && (_loc2_ = SSCollision.sweepSphereToStaticShape(this,obj)))
{
var _loc11_ = this.velocity.__get__length();
var _loc8_ = _loc2_.normal.x * this.velocity.x + _loc2_.normal.y * this.velocity.y;
var _loc6_ = _loc8_ * _loc2_.normal.x;
var _loc5_ = _loc8_ * _loc2_.normal.y;
var _loc10_ = this.velocity.x - _loc6_;
var _loc9_ = this.velocity.y - _loc5_;
var _loc3_ = undefined;
if(!(_loc3_ = _loc2_.edge.attributes.bounciness))
{
_loc3_ = 0;
}
this.velocity.x = _loc10_ - _loc3_ * _loc6_;
this.velocity.y = _loc9_ - _loc3_ * _loc5_;
var _loc7_ = this.motionTime - _loc2_.time;
this.moveTo(_loc2_.point.x + _loc2_.edge.normal.x * 1 + this.velocity.x * _loc7_,_loc2_.point.y + _loc2_.edge.normal.y * 1 + this.velocity.y * _loc7_,0);
this.collision = true;
}
break;
case SSGlobal.CLSID_MAINCHAR:
if(SSCollision.sweepSphereToSphere(this,obj,true))
{
return this.onCollision(obj);
}
break;
}
}
function onCollision(obj)
{
if(!this.inScene)
{
return undefined;
}
if(obj.active && (obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
{
obj.shiftHealth(this.healthValue,this);
var _loc2_ = new SSParticle(this.assetID,4,new Vector(obj.velocity.x * 0.5,this.velocity.y * 0.5,-300),45,SSGlobal.GRAVITY);
_loc2_.alpha = false;
_loc2_.x = this.x;
_loc2_.y = this.y;
this.world.addObject(_loc2_);
this.removeFromScene();
}
}
}